package com.ninong.ker.common.datasource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



/**
 * 数据源切换处理
 * 
 * @author cmd
 */
public class DynamicDataSourceContextHolder {
	public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class);

	private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();

	/**
	 * 设置数据源的变量
	 */
	public static void setDataSourceType(String dsType) {
		log.info("切换到{}数据源", dsType);
		CONTEXT_HOLDER.set(dsType);
	}

	/**
	 * 获得数据源的变量
	 */
	public static String getDataSourceType() {
		return CONTEXT_HOLDER.get();
	}

	/**
	 * 清空数据源变量
	 */
	public static void clearDataSourceType() {
		CONTEXT_HOLDER.remove();
	}
}
